var selectedPage = 'index';
var id_timeout;        //延时切换ID记录
var id_interval;    	//自动循环ID记录
var mouse_in_time;            //记录鼠标移入时间
var mouse_out_time;            //记录鼠标移出时间

$(function () {
    $("#" + selectedPage).addClass("selected");
})
//初始自动循环
$(function () {
    auto_toggle(1);
});

//循环
function auto_toggle(num) {
    window.focusAdv = num;
    id_interval = setInterval(function () {
        window.focusAdv = (window.focusAdv++) % 3 + 1;
        toggleAdv(window.focusAdv);
    }, 2500);
}

//手动切换图片，停止自动循环
var changeImg = function (num) {
    var myDate1 = new Date();
    mouse_in_time = myDate1.getTime();

    clearInterval(id_interval);
// 		toggleAdv(num);
    id_timeout = setTimeout("toggleAdv(" + num + ")", 100);
}

//继续自动循环
function stopChange(num) {
    var myDate2 = new Date();
    mouse_out_time = myDate2.getTime();

    clearTimeout(id_timeout);
    //停留之后的鼠标移出，以停留过的前页面作为循环起点
    if (Math.abs(mouse_out_time - mouse_in_time) > 100)
        auto_toggle(num);
    //瞬间滑过的鼠标移出，继续之前的自动循环
    else
        auto_toggle(window.focusAdv);
}

//图片切换
var toggleAdv = function (num) {
//      $('#advImg').attr("src","public/imgs/adv"+num+".png");
//		$('#imgsWrap').css("left", (1 - num) * 673)
    $('#imgsWrap').animate({left:(1 - num) * 673}, "30");
    $(".toggle-btns-wrap .toggle-btn").removeClass("selected");
    if(navigator.userAgent.indexOf("360SE")>0){
        $(".toggle-btns-wrap .toggle-btn").css({"marginTop":"0px"});
    }
    $(".toggle-btns-wrap .toggle-btn:nth-child(" + (num) + ")").addClass("selected");
    if(navigator.userAgent.indexOf("360SE")>0){
        $(".toggle-btns-wrap .toggle-btn:nth-child(" + (num) + ")").css({"marginTop":"5px"});
    }
//    $(".toggle-btn.inline-block.cancel-loc.selected").css({"marginTop":"5px"
//                });
}

